/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.text.Collator;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "province")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Province.findAll", query = "SELECT p FROM Province p"),
    @NamedQuery(name = "Province.findByIdCountry", query = "SELECT p FROM Province p WHERE p.country.idCountry = :idCountry"),
    @NamedQuery(name = "Province.findByIdProvince", query = "SELECT p FROM Province p WHERE p.idProvince = :idProvince"),
    @NamedQuery(name = "Province.findByDescription", query = "SELECT p FROM Province p WHERE p.description = :description")})
public class Province implements Serializable, Comparable<Province> {
    @OneToMany(mappedBy = "province", fetch = FetchType.LAZY)
    private List<Company> companyList;
    @OneToMany(mappedBy = "province", fetch = FetchType.LAZY)
    private List<SearchRelocatingInfoRequerimentAndOperator> searchRelocatingInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "province", fetch = FetchType.LAZY)
    private List<SearchRelocatingInfoRequerimentOrOperator> searchRelocatingInfoRequerimentOrOperatorList;
    @OneToMany(mappedBy = "offerProvince", fetch = FetchType.LAZY)
    private List<Search> searchList;
    @OneToMany(mappedBy = "province", fetch = FetchType.LAZY)
    private List<CandidateRelocatingInfo> candidateRelocatingInfoList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_PROVINCE")
    private Integer idProvince;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "DESCRIPTION")
    private String description;
    @JoinColumn(name = "COUNTRY", referencedColumnName = "ID_COUNTRY")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Country country;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "province", fetch = FetchType.LAZY)
    private List<Candidate> candidateList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "province", fetch = FetchType.LAZY)
    private List<Town> townList;

    public Province() {
    }

    public Province(Integer idProvince) {
        this.idProvince = idProvince;
    }

    public Province(Integer idProvince, String description) {
        this.idProvince = idProvince;
        this.description = description;
    }

    public Integer getIdProvince() {
        return idProvince;
    }

    public void setIdProvince(Integer idProvince) {
        this.idProvince = idProvince;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    @XmlTransient
    public List<Candidate> getCandidateList() {
        return candidateList;
    }

    public void setCandidateList(List<Candidate> candidateList) {
        this.candidateList = candidateList;
    }

    @XmlTransient
    public List<Town> getTownList() {
        return townList;
    }

    public void setTownList(List<Town> townList) {
        this.townList = townList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idProvince != null ? idProvince.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Province)) {
            return false;
        }
        Province other = (Province) object;
        if ((this.idProvince == null && other.idProvince != null) || (this.idProvince != null && !this.idProvince.equals(other.idProvince))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Province[ idProvince=" + idProvince + " ]";
    }

    @XmlTransient
    public List<CandidateRelocatingInfo> getCandidateRelocatingInfoList() {
        return candidateRelocatingInfoList;
    }

    public void setCandidateRelocatingInfoList(List<CandidateRelocatingInfo> candidateRelocatingInfoList) {
        this.candidateRelocatingInfoList = candidateRelocatingInfoList;
    }

    @XmlTransient
    public List<Search> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Search> searchList) {
        this.searchList = searchList;
    }

    @XmlTransient
    public List<SearchRelocatingInfoRequerimentAndOperator> getSearchRelocatingInfoRequerimentAndOperatorList() {
        return searchRelocatingInfoRequerimentAndOperatorList;
    }

    public void setSearchRelocatingInfoRequerimentAndOperatorList(List<SearchRelocatingInfoRequerimentAndOperator> searchRelocatingInfoRequerimentAndOperatorList) {
        this.searchRelocatingInfoRequerimentAndOperatorList = searchRelocatingInfoRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchRelocatingInfoRequerimentOrOperator> getSearchRelocatingInfoRequerimentOrOperatorList() {
        return searchRelocatingInfoRequerimentOrOperatorList;
    }

    public void setSearchRelocatingInfoRequerimentOrOperatorList(List<SearchRelocatingInfoRequerimentOrOperator> searchRelocatingInfoRequerimentOrOperatorList) {
        this.searchRelocatingInfoRequerimentOrOperatorList = searchRelocatingInfoRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<Company> getCompanyList() {
        return companyList;
    }

    public void setCompanyList(List<Company> companyList) {
        this.companyList = companyList;
    }

    @Override
    public int compareTo(Province t) {
        return Collator.getInstance().compare(this.getDescription(), t.getDescription());
    }
    
}
